import socket
import os, sys

tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp_server_socket.bind(("", 8080))
tcp_server_socket.listen(128)
while True:
    client_socket, client_ip = tcp_server_socket.accept()
    print("客户端：", client_ip, '连接')
    file_name_data = client_socket.recv(1024)
    file_name = file_name_data.decode()
    try:
        with open(file_name, 'rb') as file:
            while True:
                file_data = file.read(1024)
                if file_data:
                    client_socket.send(file_data)
                else:
                    print(file_name, "传输成功")
                    break
    except Exception as e:
        print("传输异常：", e)
    client_socket.close()
